package com.hjm.project.formalPos.posTransferRecord.controller;

import java.util.List;

import com.hjm.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.formalPos.posTransferRecord.domain.PosTransferRecord;
import com.hjm.project.formalPos.posTransferRecord.service.IPosTransferRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 划拨记录Controller
 * 
 * @author LOVE
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/formalPos/posTransferRecord")
public class PosTransferRecordController extends BaseController
{
    private String prefix = "formalPos/posTransferRecord";

    @Autowired
    private IPosTransferRecordService posTransferRecordService;

    @RequiresPermissions("formalPos:posTransferRecord:view")
    @GetMapping()
    public String posTransferRecord()
    {
        return prefix + "/posTransferRecord";
    }

    /**
     * 查询划拨记录列表
     */
    @RequiresPermissions("formalPos:posTransferRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PosTransferRecord posTransferRecord)
    {
        startPage();
        List<PosTransferRecord> list = posTransferRecordService.selectPosTransferRecordList(posTransferRecord);
        return getDataTable(list);
    }

    /**
     * 导出划拨记录列表
     */
    @RequiresPermissions("formalPos:posTransferRecord:export")
    @Log(title = "划拨记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PosTransferRecord posTransferRecord)
    {
        List<PosTransferRecord> list = posTransferRecordService.selectPosTransferRecordList(posTransferRecord);
        ExcelUtil<PosTransferRecord> util = new ExcelUtil<PosTransferRecord>(PosTransferRecord.class);
        return util.exportExcel(list, "posTransferRecord");
    }

    /**
     * 新增划拨记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存划拨记录
     */
    @RequiresPermissions("formalPos:posTransferRecord:add")
    @Log(title = "划拨记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PosTransferRecord posTransferRecord)
    {
        return toAjax(posTransferRecordService.insertPosTransferRecord(posTransferRecord));
    }

    /**
     * 修改划拨记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PosTransferRecord posTransferRecord = posTransferRecordService.selectPosTransferRecordById(id);
        mmap.put("posTransferRecord", posTransferRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存划拨记录
     */
    @RequiresPermissions("formalPos:posTransferRecord:edit")
    @Log(title = "划拨记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PosTransferRecord posTransferRecord)
    {
        return toAjax(posTransferRecordService.updatePosTransferRecord(posTransferRecord));
    }

    /**
     * 删除划拨记录
     */
    @RequiresPermissions("formalPos:posTransferRecord:remove")
    @Log(title = "划拨记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(posTransferRecordService.deletePosTransferRecordByIds(ids));
    }


    /**
     * 修改划拨记录
     */
    @GetMapping("/transfer")
    public String transfer()
    {
        return prefix + "/transfer";
    }

    /**
     * 修改保存划拨记录
     */
    @RequiresPermissions("formalPos:posTransferRecord:transfer")
    @Log(title = "划拨记录", businessType = BusinessType.UPDATE)
    @PostMapping("/transfer")
    @ResponseBody
    public AjaxResult transfer(PosTransferRecord posTransferRecord,String currentMerno) throws Exception
    {
        posTransferRecord.setOperateMan(this.getSysUser().getLoginName());
        posTransferRecord.setOperateDate(DateUtils.getDate());
        posTransferRecord.setOperateTime(DateUtils.getOnlyTime());
        return posTransferRecordService.transfer(posTransferRecord,currentMerno);
    }

    /**
     * 划拨信息查找带回
     *
     * @return
     */
    @GetMapping("/selectPosNo")
    public String selectPosNo() {
        return prefix + "/selectPosNo";
    }

    /**
     * 支行查找带回
     */
    @GetMapping("/selectTargetAgent/{currentAgent}")
    public String selectTargetAgent(@PathVariable("currentAgent") String currentAgent, ModelMap mmap)
    {
        mmap.put("currentAgent", currentAgent);
        return prefix + "/selectTargetAgent";
    }
}
